package com.justenholter.text.effects {
	
	import com.justenholter.text.effects.IEffect;
	
	/**
	 * Scrolls the new text in the specified direction.
	 * 
	 * <ul>
	 * <li><strong>TODO</strong> Add functionality for direction and loop</strong>
	 * </ul>
	 * 
	 * @author	justen holter
	 */
	public class Scroll implements IEffect {
		
		private var _direction		:Number;
		private var _newText		:String;
		private var _seperator		:String;
		
		/**
		 * Creates a new instance of Scroll.
		 * 
		 * @param	direction	A value of <code>1</code> to scroll to the left or <code>-1</code> to scroll to the right.
		 * @param	seperator	A string seperator between loops.
		 */
		public function Scroll(direction:int = 1, seperator:String = " ") {
			_direction = direction >= 1 ? 1 : -1;
			_seperator = seperator;
		}
		
		/**
		 * @inheritDoc
		 */
		public function init(curText:String, newText:String):String {
			_newText = newText + _seperator;
			return next(curText, newText);
		}
		
		/**
		 * @inheritDoc
		 */
		public function next(curText:String, newText:String):String {
			_newText = _newText.substr(_direction, _newText.length) + _newText.substr(0, _direction);
			return _newText;
		}
	}
}